package com.model;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class Thesisprogressrecord extends Model<Thesisprogressrecord>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final Thesisprogressrecord dao=new Thesisprogressrecord(); 
	
	public Record index(int stuId)
	{
		String sql="SELECT * from stu_tch WHERE student_id="+stuId+"";
		Record stu_tch=Db.findFirst(sql);
		return stu_tch;
	}
	
	public boolean save(int stuId,String text)
	{
		boolean success =false;
		String sql="SELECT stu_rela_thesis_id FROM student_rela_thesistitle WHERE stu_rela_thesis_stu = "+stuId+"";
		int stu_rela_id=Db.queryInt(sql);
//		Record thesisprogressrecord=new Record().set("prorec_student", stu_rela_id)
//				.set("prorec_content", text).set("prorec_submittime", new Date());
//		Db.save("thesisprogressrecord", "prorec_id", thesisprogressrecord);//保存新周记
		Thesisprogressrecord thc=new Thesisprogressrecord();
		success=thc.set("prorec_student", stu_rela_id)
		.set("prorec_content", text).set("prorec_submittime", new Date()).save();
		return success;
	}
	
	public Map<String, Object> table(Integer page,Integer rows,int stuId)
	{
		String sql="from check_progress_of_week WHERE student_id="+stuId+"";
		Page<Record> thesisprogressrecord=Db.paginate(page, rows, "select *", sql);
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("total", thesisprogressrecord.getTotalRow());
		m.put("rows", thesisprogressrecord.getList());
		return m;
		
	}
	
	
	/**
	 * 显示相应id的进展记录内容
	 * @param prorec_id
	 * @return
	 */
	public Map<String, Object> edit(int prorec_id)
	{
		Thesisprogressrecord thesisprogressrecord = Thesisprogressrecord.dao.findById(prorec_id);
		Map m=new HashMap();
		m.put("success", true);
		m.put("id", thesisprogressrecord.getInt("prorec_id"));
		m.put("text", thesisprogressrecord.getStr("prorec_content"));
		return m;
	}
	
	/**
	 * 更新相应的进展记录内容
	 * @param prorec_id
	 * @param text
	 * @return
	 */
	public boolean update(int prorec_id ,String text)
	{
		boolean success=false;
		success=Thesisprogressrecord.dao.findById(prorec_id).set("prorec_content", text).update();
		return success;
	}

}
